package com.woniu.hospital.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniu.hospital.domain.EquipmentType;
import com.woniu.hospital.service.IEquipmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备类型表Controller
 * 
 * @author wolf-six
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/equipment_type")
public class EquipmentTypeController extends BaseController
{
    @Autowired
    private IEquipmentTypeService equipmentTypeService;

    /**
     * 查询设备类型表列表
     */
    @RequiresPermissions("hospital:equipment_type:list")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentType equipmentType)
    {
        startPage();
        List<EquipmentType> list = equipmentTypeService.selectEquipmentTypeList(equipmentType);
        return getDataTable(list);
    }

    /**
     * 导出设备类型表列表
     */
    @RequiresPermissions("hospital:equipment_type:export")
    @Log(title = "设备类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentType equipmentType)
    {
        List<EquipmentType> list = equipmentTypeService.selectEquipmentTypeList(equipmentType);
        ExcelUtil<EquipmentType> util = new ExcelUtil<EquipmentType>(EquipmentType.class);
        util.exportExcel(response, list, "设备类型表数据");
    }

    /**
     * 获取设备类型表详细信息
     */
    @RequiresPermissions("hospital:equipment_type:query")
    @GetMapping(value = "/{equipmentTypeid}")
    public AjaxResult getInfo(@PathVariable("equipmentTypeid") Long equipmentTypeid)
    {
        return success(equipmentTypeService.selectEquipmentTypeByEquipmentTypeid(equipmentTypeid));
    }

    /**
     * 新增设备类型表
     */
    @RequiresPermissions("hospital:equipment_type:add")
    @Log(title = "设备类型表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentType equipmentType)
    {
        return toAjax(equipmentTypeService.insertEquipmentType(equipmentType));
    }

    /**
     * 修改设备类型表
     */
    @RequiresPermissions("hospital:equipment_type:edit")
    @Log(title = "设备类型表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentType equipmentType)
    {
        return toAjax(equipmentTypeService.updateEquipmentType(equipmentType));
    }

    /**
     * 删除设备类型表
     */
    @RequiresPermissions("hospital:equipment_type:remove")
    @Log(title = "设备类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentTypeids}")
    public AjaxResult remove(@PathVariable Long[] equipmentTypeids)
    {
        return toAjax(equipmentTypeService.deleteEquipmentTypeByEquipmentTypeids(equipmentTypeids));
    }
}
